package com.cskaoyan.mall.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;


/**
 * @ClassName: MyBatisUtils
 * @Description: TODO
 * @Auther 庄左
 * @Date 2022/6/28 18:18
 * @Version
 **/
public class MyBatisUtils {

    private static SqlSessionFactory factory;
    static {

        InputStream inputStream = MyBatisUtils.class.getClassLoader().getResourceAsStream("mybatis.xml");

        SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
        factory = builder.build(inputStream);
    }

    public static SqlSession getSqlSession()  {
        return factory.openSession();
    }
}
